package com.xinsoft.controller.basic;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysDocumentNumPageParam;
import com.xinsoft.entity.po.SysDocumentNum;
import com.xinsoft.service.SysDocumentNumService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/document/num")
public class SysDocumentNumController {

    @Autowired
    private SysDocumentNumService sysDocumentNumService;

    /**
     * 新增
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/add")
    public Response<?> add(@RequestBody SysDocumentNum sysDocumentNum) {
        // 参数校验
        ValidatorUtils.validateEntity(sysDocumentNum);
        return Response.succeed(sysDocumentNumService.addDocumentNum(sysDocumentNum));
    }

    /**
     * 更新
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody  SysDocumentNum sysDocumentNum) {
        // 参数校验
        ValidatorUtils.validateEntity(sysDocumentNum);
        return Response.succeed(sysDocumentNumService.editDocumentNum(sysDocumentNum));
    }

    /**
     * 获取流水号
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(sysDocumentNumService.getSysDocumentNum(id));
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        sysDocumentNumService.del(ids);
        return Response.succeed();
    }

    /**
     * 启用
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/enable")
    public Response<?> enable(@RequestBody List<Integer> ids) {
        sysDocumentNumService.enable(ids);
        return Response.succeed();
    }

    /**
     * 禁用
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/disable")
    public Response<?> disable(@RequestBody List<Integer> ids) {
        sysDocumentNumService.disable(ids);
        return Response.succeed();
    }

    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody SysDocumentNumPageParam sysDocumentNumPageParam) {
        return Response.succeed(sysDocumentNumService.findPageListByParam(sysDocumentNumPageParam));
    }

    /**
     * 不分页
     */
    @PostMapping("/list")
    public Response<?> List(@RequestBody SysDocumentNumPageParam sysDocumentNumPageParam) {
        return Response.succeed(sysDocumentNumService.findListByParam(sysDocumentNumPageParam));
    }

    /**
     * 根据单据id生成编号
     */
    @GetMapping("/getDocumentNumByDocumentId")
    public Response<?> getDocumentNumByDocumentId(@RequestParam(value = "documentId", defaultValue = "", required = true) Integer documentId) {
        return Response.succeed(sysDocumentNumService.getSysDocumentNumByDocumentId(documentId));
    }



}
